package com.mmd.manage.web;

import com.mmd.bean.CODE;
import com.mmd.bean.WebJsonBean;
import com.mmd.manage.service.UserService;
import com.mmd.manage.vo.ResetPasswordDto;
import com.mmd.manage.vo.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户
 */
@RequestMapping(value = "/api/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 添加用户
     *
     * @return
     */
    @RequestMapping(value = "/addUser")
    @ResponseBody
    public WebJsonBean addUser(UserDto userDto) {
        userService.addAdminUser(userDto);
        return new WebJsonBean(CODE.SUCCESS);
    }

    /**
     * 分页获取用户列表
     *
     * @return
     */
    @RequestMapping(value = "/getUserPageList")
    @ResponseBody
    public WebJsonBean getUserPageList(Integer pageNo, Integer pageSize ){
        pageNo = pageNo == null ? 1 : pageNo;
        pageSize = pageSize == null ? 10 : pageSize;
        return new WebJsonBean(CODE.SUCCESS, userService.getUserPageList(pageNo, pageSize));
    }

    /**
     * 冻结/解冻
     *
     * @return
     */
    @RequestMapping(value = "/isFree")
    @ResponseBody
    public WebJsonBean isFree(long uid, int isFree){
        userService.isFree(uid, isFree);
        return new WebJsonBean(CODE.SUCCESS);
    }

    /**
     * 重置密码
     *
     * @return
     */
    @RequestMapping(value = "/resetPassword")
    @ResponseBody
    public WebJsonBean resetPassword(ResetPasswordDto resetPasswordDto){
        userService.resetPassword(resetPasswordDto);
        return new WebJsonBean(CODE.SUCCESS);
    }
}
